sap.ui.define([
    "sap/ui/core/Control",
    "sap/m/Button",
    "sap/m/FlexBox",
    "sap/m/Text",
    "sap/ui/core/HTML",
    "sap/m/Link",
    "sap/m/ExpandableText",
    "sap/m/FormattedText"
], function (
    Control,
    Button,
    FlexBox,
    Text,
    HTML,
    Link,
    ExpandableText,
    FormattedText
) {
    "use strict";

    return Control.extend("autofiror.reuse.groupfeed.control.FlexB", {
        metadata: {
            properties: {
                listObject: { type: "object", defaultValue: null }
            },
            aggregations: {
                _flexbox: { type: "sap.m.FlexBox", multiple: false, visibility: "hidden" }
            },
        },

        onBeforeRendering() {
            this.setAggregation("_flexbox", new FlexBox({
                items: this._addItem(this.getListObject()),
            }).addStyleClass("wrap"));

        },

        _addItem(sourceList) {
            let list = [];
            sourceList.forEach(element => {
                if (element.type == "sap.m.Text") {
                    let t = new Text({
                        text: element.content,
                        wrapping: true
                    });
                    list.push(t);
                }
                else if (element.type == "sap.ui.core.HTML") {
                    let ht = new HTML({
                        content: element.content
                    });
                    list.push(ht);
                }
                else if (element.type == "sap.m.Link") {
                    let ht = new Link({
                        text: element.content,
                        href: element.content
                    });
                    list.push(ht);
                }
                else if (element.type == "sap.m.ExpandableText") {
                    let et = new ExpandableText({
                        text: element.content,
                        wrapping: true
                    });
                    list.push(et);
                }
                else if (element.type == "sap.m.FlexBox") {
                    let fb = new FlexBox({
                        items: this._addItem(element.content),
                    }).addStyleClass("wrap");
                    list.push(fb);
                }
            });
            console.log(list);
            return list;
        },

        renderer(oRm, oControl) {
            // 此处的参数onControl指的就是该Control组件
            oRm.openStart("div", oControl);
            // 创建一个div
            oRm.openEnd();
            oRm.renderControl(oControl.getAggregation("_flexbox"));
            oRm.close("div");
            // 闭合div
        }
    });
});